
using IQIGame.Onigao.Framework;
using NetProtocol.Enum;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    /// <summary>
    /// 虚拟的实体对象
    /// </summary>
    internal class LevelVirutalEntity : LevelPlayBaseEntity
    {
        public override uint MaxStore => 20;

        public DynLevelEntity dynEntity { protected set; get; }

        public override int id => dynEntity.id;

        public override float x => dynEntity.x;

        public override float y => dynEntity.y;

        public override float z => dynEntity.z;

        public override int dirEuler => dynEntity.dirEuler;

        public override bool active => dynEntity.active;

        public override byte interactType => dynEntity.interactType; // LevelEntityInteractType.Talk;

        public override BVHBounds2D bvhBounds { get; set; }

        public override TransformAgent transform => null;

        public override string name => dynEntity.name;

        public override int viewRange => dynEntity.levelEntityConfig.viewRange;

        public override int viewAngle => dynEntity.levelEntityConfig.viewAngle;
        public override float defaultMeterSpeed => 1;

        private void Init(DynLevelEntity dynEntity)
        {
            this.dynEntity = dynEntity;
        }

        public static LevelVirutalEntity CreateEntity(DynLevelEntity dynEntity)
        {
            var entity = ClassPool<LevelVirutalEntity>.Get();
            entity.Init(dynEntity);
            entity.OnEntityCreate();
            return entity;
        }

        public override DynLevelEntity GetDynLevelEntity()
        {
            return dynEntity;
        }

        public override LevelBuffHolder GetBuffHolder()
        {
            return dynEntity.buffHolder;
        }


        public override void EntityAddComponents()
        {

        }
        public override void SyncEntityPos(float x, float y, float z, float speedRatio, EntityMoveDirType dirType, LevelMoveReason reason)
        {
            dynEntity.UpdatePos(x, y, z);
        }

        public override void SetEntityActive(bool active)
        {
            this.dynEntity.SetActive(active);
            base.SetEntityActive(active);
        }

        public override void OnEntityBirth()
        {
        }

        public override bool ContainTag(ushort tagId)
        {
            return dynEntity.tags.Contains(tagId);
        }

        public override AnimatorAgent GetAnimator()
        {
            return null;
        }

        public override void UpdatePosToData(Vector3 position)
        {
            Vector3 logicPos = GameMathUtil.UnityPos2LogicPos(position);
            dynEntity.UpdatePos(logicPos.x, logicPos.y, logicPos.z);
        }

        public override void OnReset()
        {
            base.OnReset();
            this.dynEntity = null;
            bvhBounds = default;
        }
    }
}
